<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ScheduleTask extends Model
{

    protected $fillable = [
        'user_id',
        'name',
        'delay_time',
        'jitter_time',
        'time_type',
        'cron_expression',
        'is_active',
    ];

        /**
     * 自动转换的属性
     */
    protected $casts = [
        'is_active' => 'boolean',
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
    ];

    /**
     * 关联DawnUser
     */
    public function user()
    {
        return $this->belongsTo(DawnUser::class, 'user_id', 'dawn_id');
    }

    public function getCreatedAtAttribute($value)
    {
        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->toDateTimeString();
    }

    public function getUpdatedAtAttribute($value)
    {
        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->toDateTimeString();
    }

} 